package com.finger.crowd.mvc.config;

import com.finger.crowd.entity.Admin;
import org.apache.ibatis.jdbc.Null;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;

public class SecurityAdmin extends User {
    private static final long serialVersionUID = 521312313213L;

    // 创建原始的admin对象
    private Admin originalAdmin;

    // 声明一个有参构造器，供CrowdUserDetailsService使用
    public SecurityAdmin(Admin originalAdmin, List<GrantedAuthority> authorities) {

        // 调用父类的构造器，对用户进行检察登录
        super(originalAdmin.getLoginAcct(), originalAdmin.getUserPswd(), authorities);

        this.originalAdmin = originalAdmin;

        // 登录成功后Springsecurity 会擦除User（user实现了UserDetails）中的密码，但不会擦除原始admin中的密码，须手动擦除
        this.originalAdmin.setUserPswd(null);
    }


    public Admin getOriginalAdmin() {
        return originalAdmin;
    }

    public void setOriginalAdmin(Admin originalAdmin) {
        this.originalAdmin = originalAdmin;
    }
}
